﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.IO;
using Rolodex.ApplicationControllers;
using System.Globalization;

namespace Rolodex
{
    public static class RegistryAgent
    {
        public static RegistryKey ApplicationKey
        {
            get
            {
                RegistryKey thisKey =
                    Registry.CurrentUser.OpenSubKey("Software\\www.ne0ge0.com\\Rolodex", true);

                // If the return value is null, the key doesn't exist
                if (null == thisKey)
                {
                    thisKey =
                        Registry.CurrentUser.CreateSubKey("Software\\www.ne0ge0.com\\Rolodex");
                }

                return thisKey;
            }
        }

        public static FileInfo CardCollectionFile
        {
            get
            {
                if (null == RegistryAgent.ApplicationKey.GetValue("Card Collection File Path"))
                {
                    FileInfo thisFileInfo = new FileInfo(
                        String.Format(CultureInfo.CurrentCulture,
                        "{0}\\CardCollection.rldx",
                        Environment.GetFolderPath(Environment.SpecialFolder.Personal)));

                    RegistryAgent.ApplicationKey.SetValue(
                        "Card Collection File Path",
                        thisFileInfo.FullName);

                    return thisFileInfo;
                }

                return new FileInfo(
                    RegistryAgent.ApplicationKey.GetValue("Card Collection File Path").ToString());
            }
            set
            {
                RegistryAgent.ApplicationKey.SetValue(
                    "Card Collection File Path",
                    value.FullName);
            }
        }
    }
}
